﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="detailandmed_osa_pant", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DetailandmedOsaPant))]
    public class DetailandmedOsaPantSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDetailandmedOsaPant clazz;
        
        public DetailandmedOsaPantSerializer(IDetailandmedOsaPant clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.OsapantVoiTingimuslikVoorandamine!=null) {
                Writer.WriteStartElement("osapant_voi_tingimuslik_voorandamine");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OsapantVoiTingimuslikVoorandamine))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsaOmanikuLiik!=null) {
                Writer.WriteStartElement("osa_omaniku_liik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OsaOmanikuLiik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsaOmanikuIsikukoodRegistrikood!=null) {
                Writer.WriteStartElement("osa_omaniku_isikukood_registrikood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OsaOmanikuIsikukoodRegistrikood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsaOmanikuValisKood!=null) {
                Writer.WriteStartElement("osa_omaniku_valis_kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OsaOmanikuValisKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsaOmanikuSynniaeg!=null) {
                Writer.WriteStartElement("osa_omaniku_synniaeg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.OsaOmanikuSynniaeg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsaOmanikuNimi!=null) {
                Writer.WriteStartElement("osa_omaniku_nimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OsaOmanikuNimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsaOmanikuEesnimi!=null) {
                Writer.WriteStartElement("osa_omaniku_eesnimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OsaOmanikuEesnimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsaSuurus!=null) {
                Writer.WriteStartElement("osa_suurus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.OsaSuurus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsapandiJarjekoht!=null) {
                Writer.WriteStartElement("osapandi_jarjekoht");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.OsapandiJarjekoht))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsapandiKirjeldus!=null) {
                Writer.WriteStartElement("osapandi_kirjeldus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OsapandiKirjeldus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsapandiAlgusKpv!=null) {
                Writer.WriteStartElement("osapandi_algus_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.OsapandiAlgusKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OsapandiLoppKpv!=null) {
                Writer.WriteStartElement("osapandi_lopp_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.OsapandiLoppKpv))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("pandipidajad");
            if (clazz.Pandipidajad!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("detailandmed_pandipidaja", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Pandipidajad.Count);
                for (int x = 0; ((clazz.Pandipidajad != null) 
                            && (x < clazz.Pandipidajad.Count)); x = (x + 1)) {
                    if (clazz.Pandipidajad[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaPandipidajad = this.GetMetaData(clazz.Pandipidajad[x]);
                        Writer.WriteTypeAttribute(metaPandipidajad.TypeQualifiedName.Namespace, metaPandipidajad.TypeQualifiedName.Name);
                        metaPandipidajad.NewSerializer(clazz.Pandipidajad[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Pandipidajad");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="osapant_voi_tingimuslik_voorandamine") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osapant_voi_tingimuslik_voorandamine");
                }
                clazz.OsapantVoiTingimuslikVoorandamine = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("osapant_voi_tingimuslik_voorandamine")).Value;
            }
            if (Reader.LocalName=="osa_omaniku_liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osa_omaniku_liik");
                }
                clazz.OsaOmanikuLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("osa_omaniku_liik")).Value;
            }
            if (Reader.LocalName=="osa_omaniku_isikukood_registrikood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osa_omaniku_isikukood_registrikood");
                }
                clazz.OsaOmanikuIsikukoodRegistrikood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("osa_omaniku_isikukood_registrikood")).Value;
            }
            if (Reader.LocalName=="osa_omaniku_valis_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osa_omaniku_valis_kood");
                }
                clazz.OsaOmanikuValisKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("osa_omaniku_valis_kood")).Value;
            }
            if (Reader.LocalName=="osa_omaniku_synniaeg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osa_omaniku_synniaeg");
                }
                clazz.OsaOmanikuSynniaeg = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("osa_omaniku_synniaeg")).Value;
            }
            if (Reader.LocalName=="osa_omaniku_nimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osa_omaniku_nimi");
                }
                clazz.OsaOmanikuNimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("osa_omaniku_nimi")).Value;
            }
            if (Reader.LocalName=="osa_omaniku_eesnimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osa_omaniku_eesnimi");
                }
                clazz.OsaOmanikuEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("osa_omaniku_eesnimi")).Value;
            }
            if (Reader.LocalName=="osa_suurus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osa_suurus");
                }
                clazz.OsaSuurus = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("osa_suurus")).Value;
            }
            if (Reader.LocalName=="osapandi_jarjekoht") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osapandi_jarjekoht");
                }
                clazz.OsapandiJarjekoht = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("osapandi_jarjekoht")).Value;
            }
            if (Reader.LocalName=="osapandi_kirjeldus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osapandi_kirjeldus");
                }
                clazz.OsapandiKirjeldus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("osapandi_kirjeldus")).Value;
            }
            if (Reader.LocalName=="osapandi_algus_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osapandi_algus_kpv");
                }
                clazz.OsapandiAlgusKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("osapandi_algus_kpv")).Value;
            }
            if (Reader.LocalName=="osapandi_lopp_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>osapandi_lopp_kpv");
                }
                clazz.OsapandiLoppKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("osapandi_lopp_kpv")).Value;
            }
            if (Reader.LocalName=="pandipidajad") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_osa_pant>pandipidajad");
                }
                clazz.Pandipidajad = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedPandipidaja>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("pandipidajad");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_pandipidajad>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaPandipidajad = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedPandipidaja>(Reader, "detailandmed_pandipidaja", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedPandipidaja item = metaPandipidajad.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedPandipidaja>();
                        clazz.Pandipidajad.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaPandipidajad.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>detailandmed_osa_pant>pandipidajad", Reader.LocalName);
            }
        }
    }
}
